from rest_framework import serializers

from orders.models import OrderInfo,OrderGoods

from goods.models import SKU


class SKUSerializer(serializers.ModelSerializer):
    class Meta:
         model = SKU
         fields = ('name','default_image')

class OrderGoodsSerializer(serializers.ModelSerializer):
    sku = SKUSerializer()
    class Meta:
        model = OrderGoods
        fields = ('count','price','sku')

class OrderInfoSerializer(serializers.ModelSerializer):
    user = serializers.StringRelatedField(read_only=True)
    user_id = serializers.IntegerField(read_only=True)
    skus = OrderGoodsSerializer(many=True)
    class Meta:
        model = OrderInfo
        fields = '__all__'